import service from "@/utils/request";
import type { spuType, salesObj } from "./model/index";
import type {
  AllSpuType,
  ArraySpuSaleAttrList,
  spuImageList,
} from "./model/spuType";
enum api {
  urlSpu = "/admin/product",
  urlSale = "/admin/product/baseSaleAttrList",
  urlAddSpu = "/admin/product/saveSpuInfo",
  urlSpuImageItem = "/admin/product/spuImageList",
  urlSputSalesItem = "/admin/product/spuSaleAttrList",
  urlSpuUpdateItem = "/admin/product/updateSpuInfo",
  urlSpuSaleList = "/admin/product/spuSaleAttrList",
  urlSpuSaleImage = "/admin/product/spuImageList/",
}

export function reqSpuList(page: number, limit: number, category3Id: number) {
  return service.get<null, spuType>(api.urlSpu + `/${page}/${limit}`, {
    params: { category3Id },
  });
}
export function reqSales() {
  return service.get<null, salesObj[]>(api.urlSale);
}
export function reqAddSpu(spu: AllSpuType) {
  return service.post(api.urlAddSpu, spu);
}
export function reqSpuImageItem(id: number) {
  return service.get<null, spuImageList[]>(api.urlSpuImageItem + `/${id}`);
}
export function reqSpuSalesItem(id: number) {
  return service.get<null, ArraySpuSaleAttrList>(
    api.urlSputSalesItem + `/${id}`
  );
}
export function reqSpuUpdateItem(spu: AllSpuType) {
  console.log(spu, "2");
  return service.post(api.urlSpuUpdateItem, spu);
}
export function reqSpuSalesList(id: number) {
  return service.get<null, ArraySpuSaleAttrList>(api.urlSpuSaleList + `/${id}`);
}
export function reqSpuSaleImage(id: number) {
  return service.get<null, spuImageList[]>(api.urlSpuSaleImage + `/${id}`);
}
